var plugin_ver = 1, plugin_rev = 0;
	var actual_ver, actual_rev;


	function pluginUpdate() {
		$('#noplugin_ok').hide()
		$('#pluginupdate').show()
		var plv = plugin_ver+'.'+plugin_rev;
		var plv = '5.0';
		switch(BrowserDetect.browser) {
			case 'Safari':
				setOne('safari','safari?ver='+plv)
				break;
			case 'Chrome':
				setOne('chrome','https://chrome.google.com/webstore/detail/kfdckejfnkaemompfjhecfmhjgnchmjg')
				break;
			case 'Firefox':
				isFirefox = true;
				setOne('firefox','cstream-'+plv+'.xpi')
				break;
			case 'Opera':
				setOne('opera','cstream-'+plv+'.oex')
				break;
			default:
				$('#pluginupdate').hide()
				$('#nobrowser').show()
		}
		var actual = actual_ver>0 ? actual_ver+'.'+actual_rev : 'desconocida';
		$('#pluginupdate .info').html('Ver. instalada: '+actual+' Â» Ver. necesaria: '+plugin_ver+'.'+plugin_rev);
		
	}

	$(document).ready(function(){
		//check the url
		
		if (window.location.href.match(/\?url=/i)) {
			$('#noplugin_ply').show()
		}else {
			// Check plugin
			setTimeout(function(){
				var p = $('#plugin-Project-D-ok',parent.document), pluginok = false;
				if (p.length) {
					actual_ver = parseInt(p.attr('data-version'));
					actual_rev = parseInt(p.attr('data-revision'));
					if (actual_ver > plugin_ver || (actual_ver == plugin_ver && actual_rev >= plugin_rev)) {
						pluginok = true;
					}
				}
				if (pluginok) {
					init();
				} else {
					pluginUpdate();
				}
			},700)
			//
			if ($.browser.webkit||$.browser.opera) {
				$('#chrome_msg').show();
			}
		}	
	});
		

	function init() {
		$('#noplugin_ok').show()
		if (1>0) {
			obtLink(); 
		} else {
			$('#noplugin_ok').hide()
			$('#noplugin_no').show()
		}
	}

	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}

	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

	function eraseCookie(name) {
		createCookie(name,"",-1);
	}
	var isFirefox = false;
	function install (e) {
		if (!isFirefox) { return true; }

		var params = {
			 "Proyect-D Stream": {
				URL: e.currentTarget.href,
				IconURL: e.currentTarget.getAttribute("iconURL"),
				toString: function () { return this.URL; }
			}
		};

		InstallTrigger.install(params);
		return false;
	}
	function setOne(br, url) {
		var o = $('#pluginupdate .update');
		$('.img',o).html('<img src="http://sc.cuevana.tv/new/img/browsers/'+br+'.png" />')
		$('a',o).attr('href',(br=='chrome')?url:('http://www.cuevana.tv/player/plugins/'+url)).click(function(){
			switch (br) {
				case 'opera':
				case 'chrome':
				case 'safari':
					o.addClass('msg');
					$('.button',this).html('Actualizar pÃ¡gina luego de instalar plugin').click(function(){
						top.window.location.reload()
						return false;
					})
					break;
				case 'firefox':
					o.addClass('msg');
					$('.button',this).html('Reiniciar navegador tras instalar plugin').click(function(){
						return false;
					})
					break;
			}
		})
	}